package lambdasinaction.chap6;

import java.util.function.Consumer;

/**
 * Created by ThinkPad on 2017/8/19.
 */
public class CollectorHarness {
    public static void main(String... args) {
        System.out.println("Partitioning done in: " +
                execute(PartitionPrimeNumbers::partitionPrimesWithCustomCollector) + " msecs");
    }

    private static long execute(Consumer<Integer> primePartitioner) {
        long fastest = Long.MAX_VALUE;
        for (int i = 0;i < 10;i++) {
            long start = System.nanoTime();
            primePartitioner.accept(1_000_000);
            long duration = (System.nanoTime() - start) / 1_000_000;
            if (duration < fastest){
                fastest = duration;
            }
            System.out.println("done in " + duration);
        }
        return fastest;
    }
}
